package com.cwj.user.controller;

import com.cwj.common.domain.user;
import com.cwj.common.vo.Result;
import com.cwj.user.service.SignIn;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

@Controller
public class SignInController {

    @Resource
    private SignIn signIn;
    @RequestMapping("/signIn")
    private String SignIn(user user,@RequestParam(name = "portrait") MultipartFile headPhoto) throws IOException {
        Boolean signIn =true;
       signIn=this.signIn.isSignIn(user,headPhoto);

        return signIn ? "index" : "redirect:"+"http://192.168.0.105/";

    }

    @PostMapping("/isUserNameExit")
    @ResponseBody
  private Result isUserNameExit(@RequestParam(name = "username") String username){

        Boolean userExit = signIn.isUserNameExit(username);

        return Result.normal(userExit,null);
  }
}
